<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>numpy.dtype &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <script type="text/javascript" src="../../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../../about.html" >
    <link rel="index" title="Index" href="../../genindex.html" >
    <link rel="search" title="Search" href="../../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../../index.html" >
    <link rel="up" title="Data type objects (dtype)" href="../arrays.dtypes.html" >
    <link rel="next" title="numpy.dtype.newbyteorder" href="numpy.dtype.newbyteorder.html" >
    <link rel="prev" title="Data type objects (dtype)" href="../arrays.dtypes.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../../index.html">
      <img border=0 alt="NumPy" src="../../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="../index.html" >NumPy Reference</a></li>
          <li class="active"><a href="../arrays.html" >Array objects</a></li>
          <li class="active"><a href="../arrays.dtypes.html" accesskey="U">Data type objects (<code class="xref py py-class docutils literal notranslate"><span class="pre">dtype</span></code>)</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="numpy.dtype.newbyteorder.html" title="numpy.dtype.newbyteorder"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="../arrays.dtypes.html" title="Data type objects (dtype)"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="../arrays.dtypes.html"
                        title="previous chapter">Data type objects (<code class="xref py py-class docutils literal notranslate"><span class="pre">dtype</span></code>)</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="numpy.dtype.newbyteorder.html"
                        title="next chapter">numpy.dtype.newbyteorder</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="numpy-dtype">
<h1>numpy.dtype<a class="headerlink" href="#numpy-dtype" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="numpy.dtype">
<em class="property">class </em><code class="sig-prename descclassname">numpy.</code><code class="sig-name descname">dtype</code><span class="sig-paren">(</span><em class="sig-param">obj</em>, <em class="sig-param">align=False</em>, <em class="sig-param">copy=False</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/numpy/numpy/blob/v1.18.1/numpy/__init__.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numpy.dtype" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a data type object.</p>
<p>A numpy array is homogeneous, and contains elements described by a
dtype object. A dtype object can be constructed from different
combinations of fundamental numeric types.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>obj</strong></dt><dd><p>Object to be converted to a data type object.</p>
</dd>
<dt><strong>align</strong><span class="classifier">bool, optional</span></dt><dd><p>Add padding to the fields to match what a C compiler would output
for a similar C-struct. Can be <code class="docutils literal notranslate"><span class="pre">True</span></code> only if <em class="xref py py-obj">obj</em> is a dictionary
or a comma-separated string. If a struct dtype is being created,
this also sets a sticky alignment flag <code class="docutils literal notranslate"><span class="pre">isalignedstruct</span></code>.</p>
</dd>
<dt><strong>copy</strong><span class="classifier">bool, optional</span></dt><dd><p>Make a new copy of the data-type object. If <code class="docutils literal notranslate"><span class="pre">False</span></code>, the result
may just be a reference to a built-in data-type object.</p>
</dd>
</dl>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="numpy.result_type.html#numpy.result_type" title="numpy.result_type"><code class="xref py py-obj docutils literal notranslate"><span class="pre">result_type</span></code></a></p>
</div>
<p class="rubric">Examples</p>
<p>Using array-scalar type:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int16</span><span class="p">)</span>
<span class="go">dtype(&#39;int16&#39;)</span>
</pre></div>
</div>
<p>Structured type, one field name ‘f1’, containing int16:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s1">&#39;f1&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">int16</span><span class="p">)])</span>
<span class="go">dtype([(&#39;f1&#39;, &#39;&lt;i2&#39;)])</span>
</pre></div>
</div>
<p>Structured type, one field named ‘f1’, in itself containing a structured
type with one field:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s1">&#39;f1&#39;</span><span class="p">,</span> <span class="p">[(</span><span class="s1">&#39;f1&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">int16</span><span class="p">)])])</span>
<span class="go">dtype([(&#39;f1&#39;, [(&#39;f1&#39;, &#39;&lt;i2&#39;)])])</span>
</pre></div>
</div>
<p>Structured type, two fields: the first field contains an unsigned int, the
second an int32:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s1">&#39;f1&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">uint64</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;f2&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">)])</span>
<span class="go">dtype([(&#39;f1&#39;, &#39;&lt;u8&#39;), (&#39;f2&#39;, &#39;&lt;i4&#39;)])</span>
</pre></div>
</div>
<p>Using array-protocol type strings:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span><span class="s1">&#39;f8&#39;</span><span class="p">),(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span><span class="s1">&#39;S10&#39;</span><span class="p">)])</span>
<span class="go">dtype([(&#39;a&#39;, &#39;&lt;f8&#39;), (&#39;b&#39;, &#39;S10&#39;)])</span>
</pre></div>
</div>
<p>Using comma-separated field formats.  The shape is (2,3):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">(</span><span class="s2">&quot;i4, (2,3)f8&quot;</span><span class="p">)</span>
<span class="go">dtype([(&#39;f0&#39;, &#39;&lt;i4&#39;), (&#39;f1&#39;, &#39;&lt;f8&#39;, (2, 3))])</span>
</pre></div>
</div>
<p>Using tuples.  <code class="docutils literal notranslate"><span class="pre">int</span></code> is a fixed type, 3 the field’s shape.  <code class="docutils literal notranslate"><span class="pre">void</span></code>
is a flexible type, here of size 10:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s1">&#39;hello&#39;</span><span class="p">,(</span><span class="n">np</span><span class="o">.</span><span class="n">int64</span><span class="p">,</span><span class="mi">3</span><span class="p">)),(</span><span class="s1">&#39;world&#39;</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">void</span><span class="p">,</span><span class="mi">10</span><span class="p">)])</span>
<span class="go">dtype([(&#39;hello&#39;, &#39;&lt;i8&#39;, (3,)), (&#39;world&#39;, &#39;V10&#39;)])</span>
</pre></div>
</div>
<p>Subdivide <code class="docutils literal notranslate"><span class="pre">int16</span></code> into 2 <code class="docutils literal notranslate"><span class="pre">int8</span></code>’s, called x and y.  0 and 1 are
the offsets in bytes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">int16</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;x&#39;</span><span class="p">:(</span><span class="n">np</span><span class="o">.</span><span class="n">int8</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="s1">&#39;y&#39;</span><span class="p">:(</span><span class="n">np</span><span class="o">.</span><span class="n">int8</span><span class="p">,</span><span class="mi">1</span><span class="p">)}))</span>
<span class="go">dtype((numpy.int16, [(&#39;x&#39;, &#39;i1&#39;), (&#39;y&#39;, &#39;i1&#39;)]))</span>
</pre></div>
</div>
<p>Using dictionaries.  Two fields named ‘gender’ and ‘age’:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">({</span><span class="s1">&#39;names&#39;</span><span class="p">:[</span><span class="s1">&#39;gender&#39;</span><span class="p">,</span><span class="s1">&#39;age&#39;</span><span class="p">],</span> <span class="s1">&#39;formats&#39;</span><span class="p">:[</span><span class="s1">&#39;S1&#39;</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">]})</span>
<span class="go">dtype([(&#39;gender&#39;, &#39;S1&#39;), (&#39;age&#39;, &#39;u1&#39;)])</span>
</pre></div>
</div>
<p>Offsets in bytes, here 0 and 25:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">({</span><span class="s1">&#39;surname&#39;</span><span class="p">:(</span><span class="s1">&#39;S25&#39;</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span><span class="s1">&#39;age&#39;</span><span class="p">:(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">,</span><span class="mi">25</span><span class="p">)})</span>
<span class="go">dtype([(&#39;surname&#39;, &#39;S25&#39;), (&#39;age&#39;, &#39;u1&#39;)])</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Attributes</dt>
<dd class="field-odd"><dl class="simple">
<dt><a class="reference internal" href="numpy.dtype.alignment.html#numpy.dtype.alignment" title="numpy.dtype.alignment"><code class="xref py py-obj docutils literal notranslate"><span class="pre">alignment</span></code></a></dt><dd><p>The required alignment (bytes) of this data-type according to the compiler.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.base.html#numpy.dtype.base" title="numpy.dtype.base"><code class="xref py py-obj docutils literal notranslate"><span class="pre">base</span></code></a></dt><dd><p>Returns dtype for the base element of the subarrays, regardless of their dimension or shape.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.byteorder.html#numpy.dtype.byteorder" title="numpy.dtype.byteorder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">byteorder</span></code></a></dt><dd><p>A character indicating the byte-order of this data-type object.</p>
</dd>
<dt><a class="reference internal" href="../routines.char.html#module-numpy.char" title="numpy.char"><code class="xref py py-obj docutils literal notranslate"><span class="pre">char</span></code></a></dt><dd><p>A unique character code for each of the 21 different built-in types.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.descr.html#numpy.dtype.descr" title="numpy.dtype.descr"><code class="xref py py-obj docutils literal notranslate"><span class="pre">descr</span></code></a></dt><dd><p><em class="xref py py-obj">__array_interface__</em> description of the data-type.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.fields.html#numpy.dtype.fields" title="numpy.dtype.fields"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fields</span></code></a></dt><dd><p>Dictionary of named fields defined for this data type, or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.flags.html#numpy.dtype.flags" title="numpy.dtype.flags"><code class="xref py py-obj docutils literal notranslate"><span class="pre">flags</span></code></a></dt><dd><p>Bit-flags describing how this data type is to be interpreted.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.hasobject.html#numpy.dtype.hasobject" title="numpy.dtype.hasobject"><code class="xref py py-obj docutils literal notranslate"><span class="pre">hasobject</span></code></a></dt><dd><p>Boolean indicating whether this dtype contains any reference-counted objects in any fields or sub-dtypes.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.isalignedstruct.html#numpy.dtype.isalignedstruct" title="numpy.dtype.isalignedstruct"><code class="xref py py-obj docutils literal notranslate"><span class="pre">isalignedstruct</span></code></a></dt><dd><p>Boolean indicating whether the dtype is a struct which maintains field alignment.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.isbuiltin.html#numpy.dtype.isbuiltin" title="numpy.dtype.isbuiltin"><code class="xref py py-obj docutils literal notranslate"><span class="pre">isbuiltin</span></code></a></dt><dd><p>Integer indicating how this dtype relates to the built-in dtypes.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.isnative.html#numpy.dtype.isnative" title="numpy.dtype.isnative"><code class="xref py py-obj docutils literal notranslate"><span class="pre">isnative</span></code></a></dt><dd><p>Boolean indicating whether the byte order of this dtype is native to the platform.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.itemsize.html#numpy.dtype.itemsize" title="numpy.dtype.itemsize"><code class="xref py py-obj docutils literal notranslate"><span class="pre">itemsize</span></code></a></dt><dd><p>The element size of this data-type object.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.kind.html#numpy.dtype.kind" title="numpy.dtype.kind"><code class="xref py py-obj docutils literal notranslate"><span class="pre">kind</span></code></a></dt><dd><p>A character code (one of ‘biufcmMOSUV’) identifying the general kind of data.</p>
</dd>
<dt><strong>metadata</strong></dt><dd></dd>
<dt><a class="reference internal" href="numpy.dtype.name.html#numpy.dtype.name" title="numpy.dtype.name"><code class="xref py py-obj docutils literal notranslate"><span class="pre">name</span></code></a></dt><dd><p>A bit-width name for this data-type.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.names.html#numpy.dtype.names" title="numpy.dtype.names"><code class="xref py py-obj docutils literal notranslate"><span class="pre">names</span></code></a></dt><dd><p>Ordered list of field names, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if there are no fields.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.ndim.html#numpy.dtype.ndim" title="numpy.dtype.ndim"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndim</span></code></a></dt><dd><p>Number of dimensions of the sub-array if this data type describes a sub-array, and <code class="docutils literal notranslate"><span class="pre">0</span></code> otherwise.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.num.html#numpy.dtype.num" title="numpy.dtype.num"><code class="xref py py-obj docutils literal notranslate"><span class="pre">num</span></code></a></dt><dd><p>A unique number for each of the 21 different built-in types.</p>
</dd>
<dt><a class="reference internal" href="numpy.shape.html#numpy.shape" title="numpy.shape"><code class="xref py py-obj docutils literal notranslate"><span class="pre">shape</span></code></a></dt><dd><p>Shape tuple of the sub-array if this data type describes a sub-array, and <code class="docutils literal notranslate"><span class="pre">()</span></code> otherwise.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.str.html#numpy.dtype.str" title="numpy.dtype.str"><code class="xref py py-obj docutils literal notranslate"><span class="pre">str</span></code></a></dt><dd><p>The array-protocol typestring of this data-type object.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.subdtype.html#numpy.dtype.subdtype" title="numpy.dtype.subdtype"><code class="xref py py-obj docutils literal notranslate"><span class="pre">subdtype</span></code></a></dt><dd><p>Tuple <code class="docutils literal notranslate"><span class="pre">(item_dtype,</span> <span class="pre">shape)</span></code> if this <a class="reference internal" href="#numpy.dtype" title="numpy.dtype"><code class="xref py py-obj docutils literal notranslate"><span class="pre">dtype</span></code></a> describes a sub-array, and None otherwise.</p>
</dd>
<dt><a class="reference internal" href="numpy.dtype.type.html#numpy.dtype.type" title="numpy.dtype.type"><code class="xref py py-obj docutils literal notranslate"><span class="pre">type</span></code></a></dt><dd><p>The type object used to instantiate a scalar of this data-type.</p>
</dd>
</dl>
</dd>
</dl>
<p class="rubric">Methods</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="numpy.dtype.newbyteorder.html#numpy.dtype.newbyteorder" title="numpy.dtype.newbyteorder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">newbyteorder</span></code></a>([new_order])</p></td>
<td><p>Return a new dtype with a different byte order.</p></td>
</tr>
</tbody>
</table>
</dd></dl>

</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>